<?php

namespace App\Admin\Forms;

use App\Models\Order;
use App\Models\Tech;
use App\Models\TechFieldLog;
use Dcat\Admin\Contracts\LazyRenderable;
use Dcat\Admin\Traits\LazyWidget;
use Dcat\Admin\Widgets\Form;
use Illuminate\Support\Facades\DB;
use Symfony\Component\HttpFoundation\Response;

class LazyFormDemo extends Form implements LazyRenderable
{
    use LazyWidget;
    /**
     * 审核
     * @param array $input
     * @return Response
     */
    public function handle(array $input) {

        try{
            DB::beginTransaction();

            DB::commit();
            return $this->response()->success('审核成功')->refresh();
        }catch(\Exception $e){
            DB::rollBack();
            return $this->response()->error('审核失败'.$e->getMessage());
        }
    }

    /**
     * Build a form here.
     */
    public function form() {
        $params=$this->payload; //传过来的参数
        $this->text('真实姓名')->value();
        $this->text('身份证号')->value();
        $this->editor('富文本')->value();
        $this->radio('status')->options([1=>'通过',2=>'拒绝'])->required()
            ->when(['2'],function(Form $form){
                $form->text('reason','理由');
            });

    }
}
